﻿using System;
namespace Producers.Kis.Xtee.Riik.Ee.Producer.Kis {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="AlimonyPetitioner", Namespace="http://producers.kis.xtee.riik.ee/producer/kis", Target=typeof(AlimonyPetitioner))]
    public class AlimonyPetitionerSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IAlimonyPetitioner clazz;
        
        public AlimonyPetitionerSerializer(IAlimonyPetitioner clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("AlimonyPetitionerData");
            if (clazz.AlimonyPetitionerData!=null) {
                global::Xtee.Core.SerializationMetadata metaAlimonyPetitionerData = this.GetMetaData(clazz.AlimonyPetitionerData);
                Writer.WriteTypeAttribute(metaAlimonyPetitionerData.TypeQualifiedName.Namespace, metaAlimonyPetitionerData.TypeQualifiedName.Name);
                metaAlimonyPetitionerData.NewSerializer(clazz.AlimonyPetitionerData).WriteXml(Writer);
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : AlimonyPetitionerData");
            }
            Writer.WriteEndElement();
            if (((clazz.AlimonyClaimData == null) 
                        || (clazz.AlimonyClaimData.Count < 1m))) {
                throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "AlimonyClaimData");
            }
            for (int x = 0; ((clazz.AlimonyClaimData != null) 
                        && (x < clazz.AlimonyClaimData.Count)); x = (x + 1)) {
                Writer.WriteStartElement("AlimonyClaimData");
                if (clazz.AlimonyClaimData[x]!=null) {
                    global::Xtee.Core.SerializationMetadata metaAlimonyClaimData = this.GetMetaData(clazz.AlimonyClaimData[x]);
                    Writer.WriteTypeAttribute(metaAlimonyClaimData.TypeQualifiedName.Namespace, metaAlimonyClaimData.TypeQualifiedName.Name);
                    metaAlimonyClaimData.NewSerializer(clazz.AlimonyClaimData[x]).WriteXml(Writer);
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : AlimonyClaimData");
                }
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="AlimonyPetitionerData") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>AlimonyPetitioner>AlimonyPetitionerData");
                }
                global::Xtee.Core.SerializationMetadata metaAlimonyPetitionerData = this.GetMetaData<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IAlimonyPetitionerData>(Reader, "AlimonyPetitionerData", "http://producers.kis.xtee.riik.ee/producer/kis");
                clazz.AlimonyPetitionerData = metaAlimonyPetitionerData.NewEntity<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IAlimonyPetitionerData>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("AlimonyPetitionerData");
                    metaAlimonyPetitionerData.NewSerializer(clazz.AlimonyPetitionerData).ReadXml(Reader);
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>AlimonyPetitioner>AlimonyPetitionerData", Reader.LocalName);
            }
            clazz.AlimonyClaimData = new System.Collections.Generic.List<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IAlimonyClaimData>();
            for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                        && (Reader.LocalName == "AlimonyClaimData")); ) {
                if (Reader.LocalName=="AlimonyClaimData") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>AlimonyPetitioner>AlimonyClaimData");
                    }
                    global::Xtee.Core.SerializationMetadata metaAlimonyClaimData = this.GetMetaData<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IAlimonyClaimData>(Reader, "AlimonyClaimData", "http://producers.kis.xtee.riik.ee/producer/kis");
                    global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IAlimonyClaimData item = metaAlimonyClaimData.NewEntity<global::Producers.Kis.Xtee.Riik.Ee.Producer.Kis.IAlimonyClaimData>();
                    clazz.AlimonyClaimData.Add(item);
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("AlimonyClaimData");
                        metaAlimonyClaimData.NewSerializer(item).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>AlimonyPetitioner>AlimonyClaimData", Reader.LocalName);
                }
            }
            if ((clazz.AlimonyClaimData.Count < 1m)) {
                throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "AlimonyClaimData");
            }
        }
    }
}
